//
//  WBStatusBottomView.swift
//  Weibo
//
//  Created by xu on 2017/3/24.
//  Copyright © 2017年 xuantong. All rights reserved.
//

import UIKit

class WBStatusBottomView: UIView {
    
    //重写父类构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        self.backgroundColor = UIColor.lightGray
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 设置视图
    private func setupUI(){
        //按钮
        let retweetButton = addChildButtons(imangeName: "timeline_icon_retweet", title: "转发")
        let commentButton = addChildButtons(imangeName: "timeline_icon_comment", title: "评论")
        let unlikeButton = addChildButtons(imangeName: "timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLines()
        let line2 = addChildLines()
        
        
        
        //约束
        retweetButton.snp.makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweetButton.snp.right)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp.makeConstraints { (make) in
            make.right.top.bottom.equalTo(self)
            make.left.equalTo(commentButton.snp.right)
            
        }

        
        line1.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton.snp.right)
            make.height.equalTo(26)
        }
        
        line2.snp.makeConstraints { (make) in
            make.centerY.equalTo(self)
            make.centerX.equalTo(unlikeButton.snp.left)
            make.height.equalTo(26)


            
        }
        

        
    }
}



//MARK: 抽取按钮的方法
extension WBStatusBottomView{
    
    fileprivate func addChildButtons(imangeName:String,title:String)->UIButton {
        
        let button = UIButton()
        
        button.setTitle(title, for: UIControlState.normal)
        button.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setImage(UIImage(named:imangeName), for: UIControlState.normal)
        //设置按钮的背景图片
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: UIControlState.normal)
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background_highlighted"), for: UIControlState.highlighted)
        
        
        addSubview(button)
        
        return button
    }
    
    
    /// 创建公共竖线方法
    fileprivate func addChildLines()->UIImageView {
        
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        
        addSubview(img)
       
        return img
        
    }
    
}
